package com.zzj.portalwebsite.Controller;

import com.alibaba.fastjson.JSON;
import com.zzj.portalwebsite.Dao.Impl.ArticalInfoDaoImpl;
import com.zzj.portalwebsite.entity.article;
import com.zzj.portalwebsite.utlis.CommonResult;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/news/getNewsDetail")
public class NewsDetailController extends HttpServlet {
    private ArticalInfoDaoImpl articalInfoDao = new ArticalInfoDaoImpl();
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        response.setCharacterEncoding("UTF-8");
        response.setContentType("text/html;charset=UTF-8");

        article article = articalInfoDao.getNewsById(Integer.parseInt(request.getParameter("id")));
        System.out.println(article);
        if (article != null){
            response.getWriter().write(JSON.toJSONString(CommonResult.success(article)));
        }else{
            response.getWriter().write("获取失败");
        }
    }
}
